#include<bits/stdc++.h>
#define int long long
#define N 1000005
using namespace std;
int n;
int a[N];
int b[N];
int s1,s2;
int ans;
const int mod=998244353;
map<vector<int>,int> vis;
void dfs(int x){
    if(x>n){
        vector<int> f;
        int s=1;
        for(int i=1;i<=n;i++) f.push_back(b[i]),s=s*b[i]%mod;
        if(!s) return;
        if(vis[f]) return;
        vis[f]=1;
        ans=(ans+s)%mod;
        return;
    }
    for(int i=0;i<=a[x];i++){
        b[x]+=i;
        b[x%n+1]+=(a[x]-i);
        dfs(x+1);
        b[x]-=i;
        b[x%n+1]-=(a[x]-i);
    }
}
signed main(){
    freopen("trade.in","r",stdin);
    freopen("trade.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++){
        if(a[i]<=1) s1++;
        s2+=a[i];
    }
    if(s1==n){
        if(s2==n) printf("1");
        else printf("0");
        return 0;
    }
    dfs(1);
    printf("%lld",ans);
    return 0;
}